import { Component,Injectable} from '@angular/core';
import { SigninService} from './signin.service';
import { Router} from '@angular/router';
import { user} from '../../services/user/user.service';
import {PopService,Toaster} from 'dolphinng';
@Component({
  selector: 'signin',
  templateUrl: './signin.component.html',
  styleUrls: ['./signin.component.less'],
  providers:[SigninService]
})
@Injectable()
export class SigninComponent {

 username:string='100100100100';
  password:string='sally';
    //username:string='201210020101';
  // password:string='123456';
  isSubmitting:boolean=false;
  msg:string='';
  constructor(private siginService:SigninService,private router:Router,private pop:PopService,private toaster:Toaster){
  }
  signIn(){
    console.log(this.username);
    console.log(this.password);
    if(this.username===''){
      this.msg='请输入用户名！';
    }else if(this.password===''){
      this.msg='请输入密码！';
    }else{
      this.isSubmitting=true;
      this.msg='';
      this.siginService.signIn(this.username,this.password)
        .subscribe((res)=>{
          this.isSubmitting=false;
          console.log(res);
          if(res.status===200){
            let result=res.json();
            if(result.status===true){
              user.setUserName(result.data.username);
              user.setUserType(result.data.userType);
              user.setUserId(result.data.userId);
              user.setToken(result.data.token);
              user.setAuth(result.data.auth);
              user.setSignIn(true);
              if(result.data.userType===0) {
                this.router.navigate(['/personal']);
              }else if(result.data.userType===1){
                this.router.navigate(['/myAccount']);
              }
            }else{
              this.msg=result.message;
             /* this.pop.error({
                title:'登录失败',
                text:result.message||''
              })*/
            }
          }else{

          }
        });
    }
  }
}
